<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>BatteryCharger: SysTick.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">BatteryCharger
   &#160;<span id="projectnumber">5.0</span>
   </div>
   <div id="projectbrief">A smart charger for lead-acid batteries.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_sys_tick_8h.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle">
<div class="title">SysTick.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p><a href="_sys_tick_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a4a0c770328891d8916c1142a26481e4a"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="_sys_tick_8h.html#a4a0c770328891d8916c1142a26481e4a">TICKS_PER_SEC</a>&#160;&#160;&#160;100</td></tr>
<tr class="separator:a4a0c770328891d8916c1142a26481e4a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:aafb8d3e0fd06464b1ee0ae1edbc3c7d6"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="_sys_tick_8h.html#aafb8d3e0fd06464b1ee0ae1edbc3c7d6">SysTick_Handler</a> ()</td></tr>
<tr class="separator:aafb8d3e0fd06464b1ee0ae1edbc3c7d6"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:a1c17dcd96e9a956c281eede9ca5133ca"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="_sys_tick_8h.html#a1c17dcd96e9a956c281eede9ca5133ca">Ticks</a></td></tr>
<tr class="separator:a1c17dcd96e9a956c281eede9ca5133ca"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><dl class="section author"><dt>Author</dt><dd>K. Joseph Hass </dd></dl>
<dl class="section date"><dt>Date</dt><dd>Created: 2014-01-07T19:29:34-0500 </dd>
<dd>
Last modified: 2014-01-12T16:18:05-0500</dd></dl>
<dl class="section copyright"><dt>Copyright</dt><dd>Copyright (C) 2014 Kenneth Joseph Hass</dd>
<dd>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</dd>
<dd>
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. </dd></dl>
</div><h2 class="groupheader">Macro Definition Documentation</h2>
<a class="anchor" id="a4a0c770328891d8916c1142a26481e4a"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define TICKS_PER_SEC&#160;&#160;&#160;100</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Number of SysTick interrupts per second, which is how often the PWM duty cycle and LCD display will be updated. </p>

</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="aafb8d3e0fd06464b1ee0ae1edbc3c7d6"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void SysTick_Handler </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>The SysTick interrupt handler. </p>
<p>This function maintains the state machine for the different charging modes, looks for shorts/opens at the battery terminals, and updates the LCD display.</p>
<p>For diagnostic purposes, one GPIO pin is used to indicate when this handler is executing. This pin is defined as the FLAG1 pin, and it is set to a 1 as the first statement of the handler and is then cleared to 0 as the last statement in the handler.</p>
<p>Raw current and voltage readings have been accumulated by the ADC interrupt handler, they get converted to actual voltage and current values here. The ADC interrupt uses moving-average filters to smooth the voltage/current data so the raw values must be divided by the length of those filters as part of the conversion. <code>BattCurrent_mA</code> and <code>BattVoltage_mV</code> use long filters for better smoothing, but <code>FastVoltage_mV</code> uses a shorter filter so that faults can be detected more quickly.</p>
<p>Once the voltage and current are calculated, check to see if there appears to be a fault condition that causes the battery voltage to be too low or too high. If so, shut down the PWM and display an appropriate message.</p>
<p>If there are no faults then the normal state machine processing is done. At reset we enter one of two states. If Button 1 (the Start button) is pressed when reset occurs then we enter the CALIBRATE state. In this state the calculated battery voltage is simply printed to the LCD, without activating the PWM output. This is intended for calibration purposes. The processor must be reset to leave the CALIBRATE state.</p>
<p>If Button 1 is not pressed at reset then the process enters the WAIT4BUTTON state. The PWM output remains off and we wait for Button 1 to be pressed.</p>
<p>Once Button 1 is pressed we enter the CHECK4BATT state. At the next SysTick interrupt the first check for a faulty voltage is performed, so the CHECK4BATT state should last for just one SysTick period. If the battery voltage is within expected limits then the PWM timer is intialized and the state will transition to CC_CHARGE.</p>
<p>In the CC_CHARGE state the charger attempts to maintain the charging current at the value specified by MODE1_CURRENT_MA, and this is done by increasing the duty cycle if BattCurrent_mA is less than MODE1_CURRENT_MA or decreasing the duty cycle if BattCurrent_mA is greater than MODE1_CURRENT_MA. This constant-current charging continues until the batter voltage rises to the level specified by MODE1_VOLTAGE_MV, and then we transition to the CV_CHARGE state.</p>
<p>In the CV_CHARGE state the battery is charged at a constant voltage specified by MODE2_VOLTAGE_MV. The PWM duty cycle is adjusted up or down to maintain this charging voltage. The charger stays in this state until the charging current falls below MODE2_CURRENT_MA, and then the charger transitions to the TRICKLE mode.</p>
<p>The TRICKLE state is also a constant-voltage state, but the desired charging voltage is significantly lower than in the CV_CHARGE state. The charger remains in this state indefinitely, until the processor is reset or a faulty voltage is measured at the battery terminals.</p>
<p>In addition to maintaining the charger state, the SysTick interrupt handler writes one character to the LCD every time it is activated.</p>
<p>Finally, the Ticks variable is incremented. If the Ticks counter reaches the number of SysTick interrupts in one second then it will be cleared. The Ticks counter is used to control activities that happen at a very low rate, such as reading the temperature sensor. </p>

</div>
</div>
<h2 class="groupheader">Variable Documentation</h2>
<a class="anchor" id="a1c17dcd96e9a956c281eede9ca5133ca"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t Ticks</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Counts SysTick interrupts to support long interval timing. </p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_bfccd401955b95cf8c75461437045ac0.html">inc</a></li><li class="navelem"><a class="el" href="_sys_tick_8h.html">SysTick.h</a></li>
    <li class="footer">Generated on Mon Jan 13 2014 08:36:57 for BatteryCharger by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>
